s=input()

k = 0
if len(s)==4:
    for i in range(0,4):
        for j in range(i+1,5):
            c=int(s[i:j])
            m = 0
            for r in range(1,c+1):
                if c%r==0:
                    m=m+1
            if m == 2:
                k = max(k,c)
print(k)